package acwing._2LanQiao._8NumberTheory;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._2LanQiao._8numberTheory
 * @File : Q1243.java
 * @Author : WangRuoyu
 * @Date : 2023/3/23 11:02
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Q1243 {

    static int[] st;
    static int n;
    static int m;
    static int k;
    static int min = 200;
    static int[][] d;

    static boolean check() {
        for (int j : st) {
            if (j < 1) {
                return false;
            }
        }
        return true;
    }

    static void dfs(int s) {
        if (check()) {
            min = Math.min(s, min);
            return;
        }
        for (int i = s; i < m; ++i) {
            if (st[i] == 0) {
                for (int j = 0; j < n; ++j) {
                    if (d[j][i] > 0) {
                        for (int l = 0; l < m; ++l) {
                            st[l] += d[j][l];
                        }
                        dfs(s + 1);
                        for (int l = 0; l < m; ++l) {
                            st[l] -= d[j][l];
                        }
                    }
                }
            }
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] words = br.readLine().split(" ");

        n = Integer.parseInt(words[0]);
        m = Integer.parseInt(words[1]);
        k = Integer.parseInt(words[2]);

        st = new int[m];
        d = new int[n][m];

        for (int i = 0; i < n; ++i) {
            words = br.readLine().split(" ");
            for (int j = 0; j < k; ++j) {
                d[i][Integer.parseInt(words[j]) - 1]++;
            }
        }

        dfs(0);

        if (min == 200) {
            min = -1;
        }

        System.out.println(min);
    }
}